Special implementations of queuesThe combination of two-stack LIFO enables the queue to be FIFO, simple and efficient, and the time complexity of queuing and outbound can go to O (1)SQueue.h#ifndef _squeue_h_#define_squeue_h_typedefvoidSqueue; Squeue*squeue_create ();voidSqueue_destroy (squeue*queue);voidSqueue_clear (squeue*queue);intSqueue_append (squeue* queue,void*item);void* Squeue_retrieve (squeue*queue);void* Squeue_header (squeue*queue);intSqueue_length (squeue*queue);#endifSqueue.c#incl
figure.Define an annular queue with The subscripts at the end of the queue plus the queue length as follows:
Struct singlerearseqqueue;Typedef pvextype qelemtype;Typedef struct singlerearseqqueue * psinglerearseqqueue;Struct singlerearseqqueue{Int rear;Int Quelen;Qelemtype datapool [maxnum];};Other basic operations are not described here.
2) in the implementation of the stack, each node element in the stack is a pointer to the queue, which is defined as follows:# Define seq_stack_len 1000# D
with The subscripts at the end of the queue plus the queue length as follows:
Struct singlerearseqqueue;Typedef pvextype qelemtype;Typedef struct singlerearseqqueue * psinglerearseqqueue;Struct singlerearseqqueue{Int rear;Int Quelen;Qelemtype datapool [maxnum];};Other basic operations are not described here.
2) in the implementation of the stack, each node element in the stack is a pointer to the queue, which is defined as follows:# Define seq_stack_len 1000# Define stackelemtype psinglerearseq
A stack is used for pressing elements such
Another stack pop-up element. If an empty stack is encountered in a pop-up operation, the elements in the stack are transmitted to the stack one by one.
# Include "stdafx. H"
# Include
Template Class queue ...{
Public:
Typedef typename C: vaule_type;
Typedef typename C: size_type;
Typedef typename C conainer_type;
Explicit Queue (C const contents = C ())
: Outstack _ (contents )...{}
Bool empty () const
... {Return
:
Struct SingleRearSeqQueue;Typedef PVexType QElemType;Typedef struct SingleRearSeqQueue * PSingleRearSeqQueue;Struct SingleRearSeqQueue{Int rear;Int quelen;QElemType dataPool [MAXNUM];};Other basic operations are not described here.
2) in the implementation of the stack, each node element in the stack is a pointer to the queue, which is defined as follows:# Define SEQ_STACK_LEN 1000# Define StackElemType PSingleRearSeqQueueStruct SeqStack;Typedef struct SeqStack * PSeqStack;Struct SeqStack{Stac
Both questions are water questions. 1236 the first question is the number of points with a degree of 0 after the contraction point. The second question is how many sides are added to make the full graph strongly connected. This is a classic practice, read white books for details
Poj2186 is the number of points (the number of points in SCC) included in the unique vertex with a contraction degree of 0)
//poj1236
#include
#include
#include
#define maxn 6000
int now=0,next[maxn],head[maxn],point[max
search for a node, we press it into the stack. When we find the root point, after it is written to the stack, it represents the nodes in the extremely strong connected component. You only need to roll up the stack until the root node is out of the stack.
[Program pseudocode]
DFS (k)
INC (time); // The serial number variable for search
Low [x] = Time // The timestamp of the point at which the current node can return as far as possible
Dfn [x] = Time // Timestamp
Push (x) // inbound Stack
you can delete one edge each time you use DFS.
# Include
Question 7: ICPC 4287 proving equivalencesA can launch B, B can launch c, and now ask how many relationships are added to make all relationships equal to each other.
Analysis: it is not difficult to think of constructing a directed graph, then finding the strongly connected component in the graph, and then finding Max (ID, OD) after shrinking ). Id indicates the number of vertices whose input degree is 0, and OD indicates the nu
strong connected water problem, template title,The first one asks for at least a few points to get to any point.In fact, a strong connection to the point of contraction, to find a few degrees into the 0 points,The second question to find out to add a few edges to the point after the direction of the non-circular graph into a strong connected graphis to ask Max (Sumin, Sumout)1#include 2#include 3#include string>4#include 5#include 6 using namespacestd;7 8 Const intMAXN = 1e5 +Ten;9 intN, M, U,
Title: http://acm.hdu.edu.cn/showproblem.php?pid=1827The second strong connected component problem, for SCC also has a certain understanding, so want to summarize here; a strongly connected sub-graph with a non-strongly connected graph is called a strongly connected component (SCC), and all strongly connected components form a DAG in the original image (each strongly connected component is considered a point). The Tarjan () algorithm uses DFS to find strong connected components, we can think of
),M(1 ≤M≤ 300000 ),NIs the number of people, andMIs the number of messages. Then followedMLines, each line contain two integers si and ti. There is a blank line between every two cases. Process to the end of input.Output
For each the case, print the minimum number of groups that meet the requirement one line.Sample Input
4 41 21 32 43 4Sample Output
3Hint
Set1 = {1}, set2 = {2, 3}, set3 = {4}Author: LUO, Jiewei
Source: ZOJ Monthly, Jun 2014
#include
#include
#include
#in
title: http://acm.hdu.edu.cn/showproblem.php?pid=1269Connected components, intermittent look for a few days, today finally a strong Unicom component (SCC) template problem.Beginner SCC, understanding is not very good, is the use of DFS in the backtracking process to operate, the details of the master is not good enough. The topic test instructions is to judge whether the number of SCC in the graph is unique, the template problem;#include #include #include #include usingnamespaceStdConstintN =100
is a true connected block in all connected blocks, you can judge
Cannot organize such a competition
*/
# Include
# Include
Const int x = 100005;
Int dfn [X], low [X], stack [X], deg [X], Father [X], depth, top, bcnt;
Int f [X], Fri, n, m;
Bool use [X], instack [x];
Struct Node
{
Int V;
Node * next;
Void fun ()
{
V = 0;
Next = NULL;
}
} Edge [X], * head [X], * TMP;
Void Tarjan (int u)
{
Int V;
whether to connect, but also to find the child trees!
# Include # Include # Include Using namespace STD;# Deprecision Max 10001Vector Int dfn [Max], low [Max], index, count;Bool instack [Max];Stack Int min (int A, int B) {return a Void Tarjan (int u){Dfn [u] = low [u] = ++ index;Instack [u] = true;S. Push (U );Int I, K;For (I = 0; I {K = V [u] [I];If (! Dfn [k]){Tarjan (k );Low [u] = min (low [u], low [
connected components, we make a mark for each vertex, mark which of the vertices belongs to which strong link component, and then the point that belongs to the same strong connected component can be regarded as the same point.This is called the "pinch point."*#include #include #include #include #include #include #include #include #include #include #include using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;Const intmaxn=21010;intHEAD[M
Title Address: POJ 2762First, then determine whether the number of layers per layer in the topology network is 1 (I admit that if I don't know the problem in advance, I can't think of a topological sort.) )。 Because if there is a layer of 2, then the two fork points will not be from one point to another.The code is as follows:#include #include #include #include #include #include #include #include #include using namespace STD;#define LL __int64#define PI ACOs ( -1.0)Const intMod=1e9+7;Const intin
Bel array is 1~SCCint index,top;int SCC;Number of strongly connected componentsBOOL INSTACK[MAXN];int NUM[MAXN];Each strong connected component contains the number of points, array number 1~SCCnum arrays do not necessarily need to be combined with actualint n,m;struct Edge{int from,to,nxt;}EDGE[MAXM];void Addedge (int U,int v){Edge[tot].from=u;Edge[tot].to=v;Edge[tot].nxt=head[u];head[u]=tot++;}//chain forward star deposit diagram;void Tarjan (int u)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.